const app = getApp(),
  AJAX = app.$ajax,
  $wx = app.$wx;

Page({
  data: {
    discountCoupon: []
  },
  
  onLoad(){
    this.getMyCoupons();
  },

  onShareAppMessage(){

  },

  getDiscountCoupon(e) {
    let _this = this,
     ed = e.currentTarget.dataset;

    AJAX.getDiscountCoupon({
      loadType: 'default',
      loadMsg: '领取中...',
      id: ed.id
    }).then(([status, res, msg]) => {
      $wx.showToast(msg, {
        success(){
          _this.getMyCoupons();
        }
      });
    });
  },

  getMyCoupons(page){
    AJAX.getMyCoupons({
      loadType: 'bar',
    }).then(([status, res, msg]) => {
      if(status){
        this.setData({
          discountCoupon: res
        });
      }else{
        $wx.showToast(msg);
      }
    });
  }
});